import enum

import pygame

from Data.Variable import SCREEN_WIDTH, SCREEN_HEIGHT, SCREEN_HALF_WIDTH, FULL_WIDTH, SCREEN_HALF_HEIGHT, FULL_HEIGHT


class ScenePassStatus(enum.IntEnum):
    final_win = 0
    final_fail = 1
    over = 3
    level_pass = 4
    level_fail = 5
    normal = 6


class BaseScene:
    """
    基础场景
    """

    def __init__(self, background_path):

        self.background_path = background_path
        self.background_image = pygame.image.load(self.background_path)
        self.next_status = ScenePassStatus.normal
        self.current_surface = pygame.Surface((SCREEN_WIDTH, SCREEN_HEIGHT)).convert()
        self.view_x = None
        self.view_y = None
        if (self.background_image.get_width() <= SCREEN_WIDTH) and \
                (self.background_image.get_height() <= SCREEN_HEIGHT):
            self.sub_scene_flag = False
        else:
            self.sub_scene_flag = True

    def make_surface(self):
        if not self.sub_scene_flag:
            self.current_surface.blit(self.background_image, self.current_surface.get_rect())
        else:
            self.view_x, self.view_y = self.__boundary()
            image = self.background_image.subsurface((self.view_x, self.view_y, SCREEN_WIDTH, SCREEN_HEIGHT))
            self.current_surface.blit(image, self.current_surface.get_rect())
        self.draw_actor()
        return self.current_surface

    def get_next_status(self):
        """
        获取通关状态
        return ： 状态 ， 下一个场景
        """
        return self.get_next_status, None

    def __boundary(self):
        pos_x = self.lead_actor.pos_x
        pos_y = self.lead_actor.pos_y
        if pos_x < SCREEN_HALF_WIDTH:
            view_x = 0
        elif pos_x > FULL_WIDTH - SCREEN_HALF_WIDTH - 1:
            view_x = FULL_WIDTH - SCREEN_WIDTH - 1
        else:
            view_x = pos_x - SCREEN_HALF_WIDTH

        if pos_y < SCREEN_HALF_HEIGHT:
            view_y = 0
        elif pos_y > FULL_HEIGHT - SCREEN_HALF_HEIGHT - 1:
            view_y = FULL_HEIGHT - SCREEN_HEIGHT - 1
        else:
            view_y = pos_y - SCREEN_HALF_HEIGHT

        return view_x, view_y

    def draw_actor(self):
        pass

    def select_dialog(self, key_down, key_list):
        pass

    def show_dialog(self, surface):
        pass
